home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 556 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.8 KB  |  60 lines

  1. Path: chronicle.mti.sgi.com!austern
  2. From: rice@tiac.net (Ken Rice)
  3. Newsgroups: comp.std.c++
  4. Subject: Is this legal?
  5. Date: 26 Feb 1996 18:07:38 PST
  6. Organization: The Internet Access Company
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <rice-2602962041230001@luna.tiac.net>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. X-Original-Date: Mon, 26 Feb 1996 20:41:23 -0500
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBVAwUBMTJnf0y4NqrwXLNJAQHm+QH/cN4MXS9DQi1DnRUMLlP8gOyf9/ldboH8
  13.     tHBhdIrA3guLac4gl8+Z3sVZXzaFrTTauS3R3yEc/DYpULWmF09rjQ==
  14.     =eOjO
  15. Originator: austern@isolde.mti.sgi.com
  16.  
  17. template < class ItemType > class T
  18. {
  19. public:
  20.     T(){}
  21.     virtual ~T(){}
  22.     ItemType mArr;
  23. };
  24.  
  25. void main(void)
  26. {
  27.     T<int>* pA = nil;
  28.     dynamic_cast < T<int>* > (pA);
  29. }
  30.  
  31. Our compiler reports this error:
  32. Error   : illegal use of incomplete struct/union/class
  33. x.cp line 12   dynamic_cast < T<int>* > (pA);
  34.  
  35. Note that T<int> is not used in a way that causes it to be instantiated until
  36. it gets to the dynamic_cast. The april 95 draft sec 5.2.6 [expr.dynamic.cast]
  37. says "Types shall not be defined in a dynamic_cast."
  38.  
  39. So, the question is, does using a template that has not been instantiated
  40. before count as 'defining a type' (as the compiler seems to think), or is
  41. the code legal?
  42.  
  43. The example can be made to compile by gratuitously declaring a variable of
  44. type T<int> before the dynamic_cast line to force implicit instantiation,
  45. but that seems a bit kludgy.
  46.  
  47. Thanks,
  48. Ken Rice.
  49.  
  50. -- 
  51. Ken Rice
  52. rice@tiac.net
  53. ---
  54. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  55.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  56.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  57.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  58.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  59. ]
  60.